package com.ask.service.asyncService;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.concurrent.Future;

@Service
public class MyAsyncService {

    @Async
    public Future<String> asyncMethodWithReturn() {
        System.out.println("Async method executed by:" +
                Thread.currentThread().getName());
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return new AsyncResult<>("Async Result（ask）");
    }

    @Async("orderTaskExecutor")
    public void listAsyncMethod(String order) {
        System.out.println(order + " handled by --" + Thread.currentThread().getName());
    }
}
